<template>
    <h2>投资项目添加</h2>
<table class="table table-bordered" border="1">
    <tr>
        <td>投资项目名称</td>
        <td><input type="text" v-model="info.I_Name" placeholder="请输入项目投资名称"></td>
    </tr>
    <tr>
        <td>投资总额度</td>
        <td><input type="text" v-model="info.I_Budget" placeholder="请输入投资总额度"></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="保存" @click="AddInvest" class="btn btn-success">
        </td>
    </tr>
</table>
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref}from 'vue'

const info =ref(
    {
        I_Name:'',
        I_Budget:''
    }
)
const AddInvest = ()=>{
    if(info.value.I_Name==''){
        alert("项目名称不能为空")
        return
    }
    if(info.value.I_Budget==''){
        alert("投资总额度不能为空")
        return   
    }
    if(isNaN(Number(info.value.I_Budget))){
        alert("投资总额度必须为数字")
        return
    }
    if(Number(info.value.I_Budget)<0||Number(info.value.I_Budget)>100000000){
        alert("投资总额度必须大于0并且要小于100000000")
        return
    }
    axios.post('https://localhost:44358/api/Invest/AddInvestInfo',
        {
                I_Name:info.value.I_Name,
                I_Budget:info.value.I_Budget
        }
    ).then(res=>{
        if(res.data==-1){
            alert("项目名称重复,请重新输入")
            return
        }else if(res.data>0){
            alert("添加成功")
            location.href = "ShowInvest"
            return
        }else{
            alert("添加失败")
            return
        }
    })
}

</script>